package com.group.utils;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: 如寄
 * @version: v1.0
 * @description: com.example.demo.utils
 * @date:2021/8/27
 */
@Data
public class R {
    private Boolean success;
    private String message;
    private Integer code;
    private Map<String, Object> data;
    public static R ok() {
        R r = new R();
        r.setSuccess(true);
        r.setCode(200);
        r.setMessage("成功");
        r.setData(new HashMap<>());
        return r;
    }

    public static R error() {
        R r = new R();
        r.setSuccess(false);
        r.setCode(404);
        r.setMessage("失败");
        r.setData(new HashMap<>());
        return r;
    }

    public R data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    public R data(Map<String, Object> map) {
        this.setData(map);
        return this;
    }
}
